/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.dashboard;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFrame;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PieLabelLinkStyle;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.chart.urls.StandardPieURLGenerator;
import org.jfree.data.category.CategoryDataset;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
//import org.jfree.data.category.DefaultCategoryDataset;
import acceso.dashboard.DefaultCategoryDataset;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.annotations.CategoryLineAnnotation;
import org.jfree.chart.axis.CategoryLabelPosition;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.labels.CategoryItemLabelGenerator;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.DialShape;
import org.jfree.chart.plot.MeterInterval;
import org.jfree.chart.plot.MeterPlot;
import org.jfree.chart.plot.MultiplePiePlot;
import org.jfree.chart.plot.RingPlot;
import org.jfree.data.Range;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.data.general.ValueDataset;
import org.jfree.text.TextBlockAnchor;
import org.jfree.ui.HorizontalAlignment;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
import org.jfree.util.Rotation;
import org.jfree.util.TableOrder;

/**
 *
 * @author romulogalindo
 */
public class WorkflowImageUtil implements Serializable{

    private Document doc;
    private Element wfi;
    //variables especiales solo para los graficos que voy a devolver
    DefaultCategoryDataset dataset;
    Dataset ds;
    Dataset ds2;
    /**
     * (1) : AreaChart (2) : StackedAreaChart (3) : BarChart (4) : BarChart3D
     * (5) : LayeredBarChart (6) : StackedBarChart (7) : StackedBarChart3D (8) :
     * LineChart (9):
     */
    int type_chart = 0;
    String TITLE = "";
    String LABEL_X = "";
    String LABEL_Y = "";
    String LABEL_Y2 = "";
    int ORIENTATION = 0;
    Float PLOT_ALPHA_FOREGROUND = 0.9f;
    boolean PLOT_GRAPHIC_BORDER = false;
    boolean PLOT_GRAPHIC_SHADOW = false;
    Color PLOT_BACKGROUND = Color.WHITE;
    Double PLOT_OFFSET = 5d;
    Double PLOT_DEPTH = 0.6d;
    boolean CHART_TITLE = true;
    RectangleEdge CHART_TITLE_POSITIION = RectangleEdge.TOP;
    Font CHART_TITLE_FONT = new Font("Myriad Pro", Font.PLAIN, 18);
    Color CHART_TITLE_COLOR = Color.BLACK;
    boolean CHART_BORDER = false;
    Color CHART_BORDER_COLOR = Color.BLACK;
    BasicStroke CHART_BORDER_STROKE = new BasicStroke(1);
    float dash[] = {1, 2};
    boolean DOMAIN_LINES = true;
    BasicStroke DOMAIN_LINE_STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1, dash, 10);
    Color DOMAIN_LINE_COLOR = Color.LIGHT_GRAY;
    boolean RANGE_LINES = true;
    BasicStroke RANGE_LINE_STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1, dash, 10);
    Color RANGE_LINE_COLOR = Color.LIGHT_GRAY;
    boolean PLOT_OUTLINE = true;
    BasicStroke PLOT_OUTLINE_STROKE = new BasicStroke(1f);
    Color PLOT_OUTLINE_COLOR = Color.DARK_GRAY;
    boolean LEGEND = false;
    double LEGEND_BORDER = 0;
    RectangleEdge LEGEND_POSITIION = RectangleEdge.BOTTOM;
    Font LEGEND_FONT = new Font("Myriad Pro", Font.PLAIN, 16);
    Color LEGEND_COLOR = Color.BLACK;
    double X_LABEL_ANGLE = 0;
    Font X_LABEL_FONT = new Font("Myriad Pro", Font.BOLD, 14);
    Color X_LABEL_COLOR = Color.DARK_GRAY;
    String X_LABEL_POSITION = "";
    double X_ANGLE = 0;
    Color X_AXISLINE_COLOR = Color.BLACK;
    BasicStroke X_AXISLINE_STROKE = new BasicStroke(1f);
    Color X_AXISTICK_COLOR = Color.BLACK;
    Font X_AXISTICK_FONT = new Font("Myriad Pro", Font.PLAIN, 11);
    boolean X_AXISTICKMARKS = true;
    Color X_AXISTICKMARKS_COLOR = Color.BLACK;
    BasicStroke X_AXISTICKMARKS_STROKE = new BasicStroke(1f);
    double Y_LABEL_ANGLE = 0;
    Font Y_LABEL_FONT = new Font("Myriad Pro", Font.BOLD, 14);
    Color Y_LABEL_COLOR = Color.DARK_GRAY;
    double Y_ANGLE = 0;
    Color Y_AXISLINE_COLOR = Color.BLACK;
    BasicStroke Y_AXISLINE_STROKE = new BasicStroke(1f);
    Color Y_AXISTICK_COLOR = Color.BLACK;
    Font Y_AXISTICK_FONT = new Font("Myriad Pro", Font.PLAIN, 11);
    boolean Y_AXISTICKMARKS = true;
    Color Y_AXISTICKMARKS_COLOR = Color.BLACK;
    BasicStroke Y_AXISTICKMARKS_STROKE = new BasicStroke(1f);
    Double[] Y_RANGE = new Double[2];
    double Y2_LABEL_ANGLE = 0;
    Font Y2_LABEL_FONT = new Font("Myriad Pro", Font.BOLD, 14);
    Color Y2_LABEL_COLOR = Color.DARK_GRAY;
    double Y2_ANGLE = 0;
    Color Y2_AXISLINE_COLOR = Color.BLACK;
    BasicStroke Y2_AXISLINE_STROKE = new BasicStroke(1f);
    Color Y2_AXISTICK_COLOR = Color.BLACK;
    Font Y2_AXISTICK_FONT = new Font("Myriad Pro", Font.PLAIN, 11);
    boolean Y2_AXISTICKMARKS = true;
    Color Y2_AXISTICKMARKS_COLOR = Color.BLACK;
    BasicStroke Y2_AXISTICKMARKS_STROKE = new BasicStroke(1f);
    int Y2_AXIS_TYPE = 0;//Numeric por default
    Double[] Y2_RANGE = new Double[2];
    boolean TOOLTIP = false;
    Font TOOLTIP_FONT = new Font("Myriad Pro", Font.BOLD, 14);
    Color TOOLTIP_COLOR = Color.BLACK;
    String TOOLTIP_FORMAT = "{0}";
    boolean URL = false;
    String URL_LINK_1 = "";
    String URL_LINK_2 = "";
    String URL_LINK_3 = "";
    //Correspondiente a los label del tipo pie y ring
    boolean LABEL = false;
    String LABEL_FORMAT = "{0} - {2}";
    RectangleInsets LABEL_OFFSET = new RectangleInsets(-12, -20, -12, -20);
    Color LABEL_OUTLINECOLOR = new Color(0, 0, 0, 0);
    Color LABEL_BACKGROUNDCOLOR = new Color(0, 0, 0, 0);
    Color LABEL_SHADOWCOLOR = new Color(0, 0, 0, 0);
    Font LABEL_FONT = new Font("Myriad Pro", Font.PLAIN, 10);
    int LABEL_TYPE = 1;    
    //-------------------------------------------------------
    private int width = 500;
    private int height = 350;
    List explodes;
    long id_frawor = 0L;
    int co_pagina = 0;
    int co_conten = 0;

    public WorkflowImageUtil(Document doc) {
        this(doc, 0L, 0, 0);
    }

    public WorkflowImageUtil(Document doc, long id_frawor, int co_pagina, int co_conten) {
        this.doc = doc;
        this.id_frawor = id_frawor;
        this.co_pagina = co_pagina;
        this.co_conten = co_conten;
    }

    public String get_atribute_from_node(Node nodeName, String attibuteName) {
        try {
            return nodeName.getAttributes().getNamedItem(attibuteName).getNodeValue();
        } catch (Exception ep) {
            return null;
        }
    }

    public Color makeColor(String color, Color d) {
        try {
            if (color.startsWith("#")) {
                return new Color(Integer.parseInt(color.replace("#", ""), 16));
            } else if (color.contentEquals("transaparent")) {
                return new Color(0, 0, 0, 0);
            } else {
                Field field = Color.class.getField(color);
                return (Color) field.get(null);
            }
        } catch (Exception ep) {
            return (d == null) ? Color.BLACK : d; // Not defined
        }
    }

    public Font makeFont(String sfont) {
        try {
            String[] font = sfont.split(",");
            int font_style = 0;
            if (font[1].trim().contentEquals("plain")) {
                font_style = Font.PLAIN;
            } else if (font[1].trim().contentEquals("bold")) {
                font_style = Font.BOLD;
            } else if (font[1].trim().contentEquals("italic")) {
                font_style = Font.ITALIC;
            }
            return new Font(font[0].trim(), font_style, Integer.parseInt(font[2].trim()));
        } catch (Exception ep) {
            return new Font("Myriad Pro", Font.PLAIN, 11);
        }
    }

    public JFreeChart proces() throws Exception {
//        this.id_frawor = id_frawor;
//        this.co_pagina = co_pagina;
//        this.co_conten = co_conten;

        doc.getDocumentElement().normalize();
        wfi = doc.getDocumentElement();

        NodeList charts = wfi.getElementsByTagName("chart");

        if (charts.getLength() > 0) {
            Node chart = charts.item(0);
            String chartType = get_atribute_from_node(chart, "type");
            if (chartType != null) {
                System.out.println("typo de grafico:" + chartType);
                switch (chartType.toLowerCase()) {
                    case "areachart":
                        ds = new DefaultCategoryDataset();
                        type_chart = 1;
                        break;
                    case "stackedareachart":
                        ds = new DefaultCategoryDataset();
                        type_chart = 2;
                        break;
                    case "barchart":
                        ds = new DefaultCategoryDataset();
                        ds2 = new DefaultCategoryDataset();
                        type_chart = 3;
                        break;
                    case "barchart3d":
                        ds = new DefaultCategoryDataset();
                        ds2 = new DefaultCategoryDataset();
                        type_chart = 4;
                        break;
                    case "layeredbarchart":
                        ds = new DefaultCategoryDataset();
                        ds2 = new DefaultCategoryDataset();
                        type_chart = 5;
                        break;
                    case "stackedbarchart":
                        ds = new DefaultCategoryDataset();
                        ds2 = new DefaultCategoryDataset();
                        type_chart = 6;
                        break;
                    case "stackedbarchart3d":
                        ds = new DefaultCategoryDataset();
                        ds2 = new DefaultCategoryDataset();
                        type_chart = 7;
                        break;
                    case "linechart":
                        ds = new DefaultCategoryDataset();
                        type_chart = 8;
                        break;
                    case "linechart3d":
                        ds = new DefaultCategoryDataset();
                        type_chart = 9;
                        break;
                    case "piechart":
                        ds = new DefaultPieDataset();
                        type_chart = 10;
                        explodes = new ArrayList();
                        break;
                    case "piechart3d":
                        ds = new DefaultPieDataset();
                        type_chart = 11;
                        explodes = new ArrayList();
                        break;
                    case "multiplepiechart":
                        ds = new DefaultCategoryDataset();
                        type_chart = 12;
                        break;
                    case "multiplepiechart3d":
                        ds = new DefaultCategoryDataset();
                        type_chart = 13;
                        break;
                    case "ringchart":
                        ds = new DefaultPieDataset();
                        type_chart = 14;
                        explodes = new ArrayList();
                        break;
                    case "multipleringchart":
                        ds = new DefaultPieDataset();
                        type_chart = 15;
                        explodes = new ArrayList();
                        break;
                    case "meterchart":
                        ds = new DefaultValueDataset();
                        type_chart = 16;
                        break;
                    case "dialchart":
                        ds = new DefaultValueDataset();
                        type_chart = 17;
                        break;
                    case "percentagebarchart":
                        ds = new DefaultCategoryDataset();
                        type_chart = 18;
                        break;
                    case "percentagebarchart3d":
                        ds = new DefaultCategoryDataset();
                        type_chart = 19;
                        break;
                }


                Node gorupdatasetNode = null;
                Node configurationNode = null;

                gorupdatasetNode = ((Element) chart).getElementsByTagName("groupdataset").item(0);
                configurationNode = ((Element) chart).getElementsByTagName("configuration").item(0);

                NodeList datasets = ((Element) gorupdatasetNode).getElementsByTagName("dataset");
                for (int i = 0; i < datasets.getLength(); i++) {
                    Node dataset = datasets.item(i);
                    String datasetName = get_atribute_from_node(dataset, "name") != null ? get_atribute_from_node(dataset, "name") : "[" + i + "]";
//                    String datasetValue = get_atribute_from_node(dataset, "value") != null ? get_atribute_from_node(dataset, "value") : datasetName;
//                    String datasetValue = get_atribute_from_node(dataset, "value") != null ? get_atribute_from_node(dataset, "value") : "";
                    String datasetValue = get_atribute_from_node(dataset, "code") != null ? get_atribute_from_node(dataset, "code") : "";
                    String datasetUrl = get_atribute_from_node(dataset, "url") != null ? get_atribute_from_node(dataset, "url") : "";
                    String datasetColor = get_atribute_from_node(dataset, "color") != null ? get_atribute_from_node(dataset, "color") : "default";//dataset_attributes_color != null) ? dataset_attributes_color.getNodeValue() : "default";
                    boolean datasetExtra = get_atribute_from_node(dataset, "extra") != null ? Boolean.parseBoolean(get_atribute_from_node(dataset, "extra")) : false;//dataset_attributes_extra != null) ? Boolean.parseBoolean(dataset_attributes_extra.getNodeValue()) : false;

                    NodeList sets = ((Element) dataset).getElementsByTagName("set");
                    for (int y = 0; y < sets.getLength(); y++) {
                        Node set = sets.item(y);//elemento set

                        String setName = get_atribute_from_node(set, "name");
                        String setValue = get_atribute_from_node(set, "value");
                        String setCode = get_atribute_from_node(set, "code") != null ?get_atribute_from_node(set, "code"):setName ;
//                        System.out.println("code:"+setCode+"|setValue:"+setValue+"|setName:"+setName);
                        if (setName != null & setValue != null) {
                            switch (type_chart) {
                                case 1: {//stacked
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 2: {//stackedarea
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 3: {//barchar
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ((!datasetExtra) ? ds : ds2)).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 4: {//barchar3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ((!datasetExtra) ? ds : ds2)).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 5: {//layerbar
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 6: {//stackedbarchar
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ((!datasetExtra) ? ds : ds2)).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 7: {//stackedbarchar3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ((!datasetExtra) ? ds : ds2)).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 8: {//linechart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 9: {//linechart3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, setCode, datasetUrl, datasetColor);
                                    break;
                                }
                                case 10: {//piechart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultPieDataset) ds).setValue(setName, db, datasetValue, datasetUrl);
                                    if (get_atribute_from_node(set, "explotar") != null && get_atribute_from_node(set, "explotar").equals("true")) {
                                        explodes.add(setName);
                                    }
                                    break;
                                }
                                case 11: {//piechart3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultPieDataset) ds).setValue(setName, db, datasetValue, datasetUrl);
                                    if (get_atribute_from_node(set, "explotar") != null && get_atribute_from_node(set, "explotar").equals("true")) {
                                        explodes.add(setName);
                                    }
                                    break;
                                }
                                case 12: {//multiplepiechart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                                case 13: {//MultiplePieChart3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                                case 14: {//ringchart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultPieDataset) ds).setValue(setName, db, datasetValue, datasetUrl);
                                    if (get_atribute_from_node(set, "explotar") != null && get_atribute_from_node(set, "explotar").equals("true")) {
                                        explodes.add(setName);
                                    }
                                    break;
                                }
                                case 15: {//linechart2
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                                case 16: {//meterchart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultValueDataset) ds).setValue(db);
                                    break;
                                }
                                case 17: {//dialchart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                                case 18: {//percentagebarchart
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                                case 19: {//percentagebarchart3d
                                    double db = Double.parseDouble(setValue);
                                    ((DefaultCategoryDataset) ds).addValue(db, datasetName, datasetValue, setName, datasetUrl, datasetColor);
                                    break;
                                }
                            }
                        }
                    }
                }

                NodeList configurationSets = ((Element) configurationNode).getElementsByTagName("set");
                for (int i = 0; i < configurationSets.getLength(); i++) {
                    Node set = configurationSets.item(i);//elemento set

                    String setName = get_atribute_from_node(set, "name");
                    String setValue = get_atribute_from_node(set, "value");

                    if (setName != null & setValue != null) {
//                        setValue = setValue.toLowerCase();
                        switch (setName.toLowerCase()) {
                            case "plot.alpha_foreground":
                                PLOT_ALPHA_FOREGROUND = Float.parseFloat(setValue.toLowerCase().trim());
                                break;
                            case "plot.graphic_border":
                                PLOT_GRAPHIC_BORDER = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "plot.graphic_shadow":
                                PLOT_GRAPHIC_SHADOW = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "title":
                                TITLE = setValue;
                                break;
                            case "chart.title":
                                CHART_TITLE = setValue.contentEquals("true") ? true : false;
                                break;
                            case "chart.title_position":
                                if (setValue.toLowerCase().contentEquals("top")) {
                                    CHART_TITLE_POSITIION = RectangleEdge.TOP;
                                } else if (setValue.contentEquals("bottom")) {
                                    CHART_TITLE_POSITIION = RectangleEdge.BOTTOM;
                                } else if (setValue.contentEquals("right")) {
                                    CHART_TITLE_POSITIION = RectangleEdge.RIGHT;
                                } else if (setValue.contentEquals("left")) {
                                    CHART_TITLE_POSITIION = RectangleEdge.LEFT;
                                }
                                break;
                            case "chart.title_font":
                                CHART_TITLE_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "chart.title_color":
                                CHART_TITLE_COLOR = makeColor(setValue.toLowerCase(), CHART_TITLE_COLOR);
                                break;
                            case "chart.border":
                                CHART_BORDER = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "chart.border_color":
                                CHART_BORDER_COLOR = makeColor(setValue.toLowerCase(), CHART_TITLE_COLOR);
                                break;
                            case "chart.border_stroke":
                                CHART_BORDER_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "plot.outline":
                                PLOT_OUTLINE = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "plot.outline_stroke":
                                PLOT_OUTLINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "plot.outline_color":
                                PLOT_OUTLINE_COLOR = makeColor(setValue.toLowerCase(), PLOT_OUTLINE_COLOR);
                                break;
                            case "plot.background":
                                PLOT_BACKGROUND = makeColor(setValue.toLowerCase(), PLOT_BACKGROUND);
                                break;
                            case "plot.offset":
                                PLOT_OFFSET = Double.parseDouble(setValue.toLowerCase());
                                break;
                            case "plot.depth":
                                PLOT_DEPTH = Double.parseDouble(setValue.toLowerCase());
                                break;
                            case "plot.domain_line":
                                DOMAIN_LINES = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "plot.domain_line_stroke":
                                DOMAIN_LINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, Float.parseFloat(setValue.toLowerCase().trim()), dash, 10);
                                break;
                            case "plot.domain_line_color":
                                DOMAIN_LINE_COLOR = makeColor(setValue.toLowerCase(), DOMAIN_LINE_COLOR);
                                break;
                            case "plot.range_line":
                                RANGE_LINES = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "plot.range_line_stroke":
                                RANGE_LINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, Float.parseFloat(setValue.toLowerCase().trim()), dash, 10);
                                break;
                            case "plot.range_line_color":
                                RANGE_LINE_COLOR = makeColor(setValue.toLowerCase(), RANGE_LINE_COLOR);
                                break;
                            case "x.title":
                                LABEL_X = setValue;
                                break;
                            case "x.label_angle":
                                X_LABEL_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "x.label_font":
                                X_LABEL_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "x.label_color":
                                X_LABEL_COLOR = makeColor(setValue.toLowerCase(), X_LABEL_COLOR);
                                break;
                            case "x.label_position":
                                X_LABEL_POSITION = setValue.toLowerCase();
                                break;
                            case "x.angle":
                                X_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "x.laxisline_color":
                                X_AXISLINE_COLOR = makeColor(setValue.toLowerCase(), X_AXISLINE_COLOR);
                                break;
                            case "x.laxisline_stroke":
                                X_AXISLINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "x.axistick_font":
                                X_AXISTICK_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "x.axistick_color":
                                X_AXISTICK_COLOR = makeColor(setValue.toLowerCase(), X_AXISTICK_COLOR);
                                break;
                            case "x.axistickmarks":
                                X_AXISTICKMARKS = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "x.axistickmarks_color":
                                X_AXISTICKMARKS_COLOR = makeColor(setValue.toLowerCase(), X_AXISTICKMARKS_COLOR);
                                break;
                            case "x.axistickmarks_stroke":
                                X_AXISTICKMARKS_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "y.title":
                                LABEL_Y = setValue;
                                break;
                            case "y.label_angle":
                                Y_LABEL_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "y.label_font":
                                Y_LABEL_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "y.label_color":
                                Y_LABEL_COLOR = makeColor(setValue.toLowerCase(), Y_LABEL_COLOR);
                                break;
                            case "y.angle":
                                Y_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "y.axisline_color":
                                Y_AXISLINE_COLOR = makeColor(setValue.toLowerCase(), Y_AXISLINE_COLOR);
                                break;
                            case "y.axisline_stroke":
                                Y_AXISLINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "y.axistick_font":
                                Y_AXISTICK_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "y.axistick_color":
                                Y_AXISTICK_COLOR = makeColor(setValue.toLowerCase(), Y_AXISTICK_COLOR);
                                break;
                            case "y.axistickmarks":
                                Y_AXISTICKMARKS = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "y.axistickmarks_color":
                                Y_AXISTICKMARKS_COLOR = makeColor(setValue.toLowerCase(), Y_AXISTICKMARKS_COLOR);
                                break;
                            case "y.axistickmarks_stroke":
                                Y_AXISTICKMARKS_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "y.range":
                                Y_RANGE[0] = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                Y_RANGE[1] = Double.parseDouble(setValue.toLowerCase().trim().split(";")[1]);
                                break;
                            case "y2.title":
                                LABEL_Y2 = setValue;
                                break;
                            case "y2.label_angle":
                                Y2_LABEL_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "y2.label_font":
                                Y2_LABEL_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "y2.label_color":
                                Y2_LABEL_COLOR = makeColor(setValue.toLowerCase(), Y2_LABEL_COLOR);
                                break;
                            case "y2.angle":
                                Y2_ANGLE = Double.parseDouble(setValue.toLowerCase().trim());
                                break;
                            case "y2.axisline_color":
                                Y2_AXISLINE_COLOR = makeColor(setValue.toLowerCase(), Y2_AXISLINE_COLOR);
                                break;
                            case "y2.axisline_stroke":
                                Y2_AXISLINE_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "y2.axistick_font":
                                Y2_AXISTICK_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "y2.axistick_color":
                                Y2_AXISTICK_COLOR = makeColor(setValue.toLowerCase(), Y2_AXISTICK_COLOR);
                                break;
                            case "y2.axistickmarks":
                                Y2_AXISTICKMARKS = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "y2.axistickmarks_color":
                                Y2_AXISTICKMARKS_COLOR = makeColor(setValue.toLowerCase(), Y2_AXISTICKMARKS_COLOR);
                                break;
                            case "y2.axistickmarks_stroke":
                                Y2_AXISTICKMARKS_STROKE = new BasicStroke(Float.parseFloat(setValue.toLowerCase().trim()));
                                break;
                            case "y2.axis_type":
                                if (setValue.toLowerCase().contentEquals("numeric")) {
                                    Y2_AXIS_TYPE = 0;
                                } else if (setValue.toLowerCase().contentEquals("integer")) {
                                    Y2_AXIS_TYPE = 1;
                                } else if (setValue.toLowerCase().contentEquals("currency")) {
                                    Y2_AXIS_TYPE = 2;
                                } else if (setValue.toLowerCase().contentEquals("porcent")) {
                                    Y2_AXIS_TYPE = 3;
                                }
                                break;
                            case "y2.range":
                                Y2_RANGE[0] = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                Y2_RANGE[1] = Double.parseDouble(setValue.toLowerCase().trim().split(";")[1]);
                                break;
                            case "orientation":
                                ORIENTATION = setValue.toLowerCase().contentEquals("vertical") ? 1 : 0;
                                break;
                            case "legend":
                                LEGEND = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "legend.border":
                                LEGEND_BORDER = Double.parseDouble(setValue.toLowerCase());
                                break;
                            case "legend.position":
                                if (setValue.toLowerCase().contentEquals("top")) {
                                    LEGEND_POSITIION = RectangleEdge.TOP;
                                } else if (setValue.toLowerCase().contentEquals("bottom")) {
                                    LEGEND_POSITIION = RectangleEdge.BOTTOM;
                                } else if (setValue.toLowerCase().contentEquals("right")) {
                                    LEGEND_POSITIION = RectangleEdge.RIGHT;
                                } else if (setValue.toLowerCase().contentEquals("left")) {
                                    LEGEND_POSITIION = RectangleEdge.LEFT;
                                }
                                break;
                            case "legend.font":
                                LEGEND_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "legend.color":
                                LEGEND_COLOR = makeColor(setValue.toLowerCase(), LEGEND_COLOR);
                                break;
                            case "tooltip":
                                TOOLTIP = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "tooltip.font":
                                TOOLTIP_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "tooltip.color":
                                TOOLTIP_COLOR = makeColor(setValue.toLowerCase(), TOOLTIP_COLOR);
                                break;
                            case "tooltip.format":
                                TOOLTIP_FORMAT = setValue.toLowerCase();
                                break;
                            case "label":
                                LABEL = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "label.format":
                                LABEL_FORMAT = setValue.toLowerCase();
                                break;
                            case "label.outlinecolor":
                                LABEL_OUTLINECOLOR = makeColor(setValue.toLowerCase(), LABEL_OUTLINECOLOR);
                                break;
                            case "label.backgroundcolor":
                                LABEL_BACKGROUNDCOLOR = makeColor(setValue.toLowerCase(), LABEL_BACKGROUNDCOLOR);
                                break;
                            case "label.shadowcolor":
                                LABEL_SHADOWCOLOR = makeColor(setValue.toLowerCase(), LABEL_SHADOWCOLOR);
                                break;
                            case "label.font":
                                LABEL_FONT = makeFont(setValue.toLowerCase());
                                break;
                            case "label.offset":
                                Double top = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                Double right = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                Double bottom = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                Double left = Double.parseDouble(setValue.toLowerCase().trim().split(";")[0]);
                                LABEL_OFFSET = new RectangleInsets(top, right, bottom, left);
                                break;
                            case "label.type":
                                LABEL_TYPE = Integer.parseInt(setValue.toLowerCase());
                                break;
                            case "url":
                                URL = setValue.toLowerCase().contentEquals("true") ? true : false;
                                break;
                            case "url.link":
                                String[] link = setValue.toLowerCase().split(";");
                                URL_LINK_1 = link[0];
                                URL_LINK_2 = link[1];
                                URL_LINK_3 = link[2];
                                break;
                            case "width":
                                setWidth(Integer.parseInt(setValue.toLowerCase()));
                                break;
                            case "height":
                                setHeight(Integer.parseInt(setValue.toLowerCase()));
                                break;
                        }

                    }
//                    }
                }

                //-------------------
            } else {
                throw new Exception("No se a proporcionado un tipo de gráfico valido.");
            }
        } else {
            throw new Exception("No existen gráficos a mostrar.");
        }

        switch (type_chart) {//area
            case 1: {
                // <editor-fold defaultstate="collapsed" desc="areachart">
                JFreeChart chart = ChartFactory.createAreaChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);

                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            case 2: {//stacked
                // <editor-fold defaultstate="collapsed" desc="stackedchart">
                JFreeChart chart = ChartFactory.createStackedAreaChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);
                return chart;
                // </editor-fold>
            }
            case 3: {//barchart
                // <editor-fold defaultstate="collapsed" desc="barchart">
                JFreeChart chart = ChartFactory.createBarChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);
                return chart;
                // </editor-fold>
            }
            case 4: {//barchart3d
                // <editor-fold defaultstate="collapsed" desc="barchart3d">
                JFreeChart chart = ChartFactory.createBarChart3D(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);

                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            case 5: {//BARCHART3D
                // <editor-fold defaultstate="collapsed" desc="barchart3d">
                JFreeChart chart = ChartFactory.createBarChart3D(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);

                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            case 6: {//stackedbarchar
                // <editor-fold defaultstate="collapsed" desc="stackedbarchar">
                JFreeChart chart = ChartFactory.createStackedBarChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);

                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            case 7: {//stackedbarchar3d
                // <editor-fold defaultstate="collapsed" desc="stackedbarchar3d">
                JFreeChart chart = ChartFactory.createStackedBarChart3D(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);
                return chart;
                // </editor-fold>
            }
            case 8: {//LineChart
                // <editor-fold defaultstate="collapsed" desc="linechart">
                JFreeChart chart = ChartFactory.createLineChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);
                return chart;
                // </editor-fold>
            }
            case 9: {//LineChart3D
                // <editor-fold defaultstate="collapsed" desc="linechart3d">
                JFreeChart chart = ChartFactory.createLineChart3D(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);
                return chart;
                // </editor-fold>
            }
            case 10: {//PieChart
                // <editor-fold defaultstate="collapsed" desc="piechart">
                JFreeChart chart = ChartFactory.createPieChart(TITLE, (DefaultPieDataset) ds, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                PiePlot plot = (PiePlot) chart.getPlot();
                settter_values_to_Plot_Pie(plot);
                return chart;
                // </editor-fold>
            }
            case 11: {//PieChart3d
                // <editor-fold defaultstate="collapsed" desc="piechart3d">
                JFreeChart chart = ChartFactory.createPieChart3D(TITLE, (DefaultPieDataset) ds, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                PiePlot plot = (PiePlot) chart.getPlot();
                settter_values_to_Plot_Pie(plot);
                return chart;
                // </editor-fold>
            }
            case 12: {//multiplePieChart
                // <editor-fold defaultstate="collapsed" desc="multipiechart">
                JFreeChart chart = ChartFactory.createMultiplePieChart(TITLE, (DefaultCategoryDataset) ds, TableOrder.BY_ROW, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                settter_values_to_Plot_MultiplePie((MultiplePiePlot) chart.getPlot());
//                settter_values_to_Plot_Pie((PiePlot) chart.getPlot());
                return chart;
                // </editor-fold>
            }
            case 13: {//multipiechart3d
                // <editor-fold defaultstate="collapsed" desc="multipiechart3d">
                JFreeChart chart = ChartFactory.createMultiplePieChart3D(TITLE, (DefaultCategoryDataset) ds, TableOrder.BY_ROW, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
                settter_values_to_Plot_MultiplePie((MultiplePiePlot) chart.getPlot());
                return chart;
                // </editor-fold>
            }
            case 14: {//ringChart
                // <editor-fold defaultstate="collapsed" desc="ringchart">
                JFreeChart chart = ChartFactory.createRingChart(TITLE, (DefaultPieDataset) ds, LEGEND, TOOLTIP, URL);
                settter_values_to_Plot_Ring((RingPlot) chart.getPlot());
                settter_values_to_char(chart);
                return chart;
                // </editor-fold>
            }
            case 15: {//multipleringChart
                // <editor-fold defaultstate="collapsed" desc="multipleringchart">
                JFreeChart chart = ChartFactory.createRingChart(TITLE, (DefaultPieDataset) ds, LEGEND, TOOLTIP, URL);

                settter_values_to_char(chart);
                settter_values_to_Plot_Ring((RingPlot) chart.getPlot());
                return chart;
                // </editor-fold>
            }

            case 16: {//Metercharet
                // <editor-fold defaultstate="collapsed" desc="meterplot">
                MeterPlot plot = new MeterPlot((ValueDataset) ds);

                plot.setRange(new Range(0.0D, 80.0D));
                plot.addInterval(new MeterInterval("Normal", new Range(0.0D, 35.0D), Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
                plot.addInterval(new MeterInterval("Warning", new Range(35.0D, 50.0D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
                plot.addInterval(new MeterInterval("Critical", new Range(50.0D, 80.0D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128)));
                plot.setNeedlePaint(Color.darkGray);
                plot.setDialBackgroundPaint(Color.white);
                plot.setDialOutlinePaint(Color.gray);
                plot.setDialShape(DialShape.CHORD);
//                plot.setMeterAngle(260);
                plot.setMeterAngle(180);
                plot.setTickLabelsVisible(true);
//                plot.setTickLabelFont(new Font("Dialog", 1, 10));
//                plot.setTickLabelPaint(Color.darkGray);
                plot.setTickSize(20.0D);
                plot.setTickPaint(Color.lightGray);
                plot.setValuePaint(Color.black);
//                plot.setValueFont(new Font("Dialog", 1, 14));

                JFreeChart chart = new JFreeChart(TITLE, CHART_TITLE_FONT, plot, LEGEND);

//                JFreeChart chart = ChartFactory.createMultiplePieChart3D(TITLE, (DefaultCategoryDataset) ds, TableOrder.BY_ROW, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
//
//                MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();

//                CategoryPlot categoryplot = chart.getCategoryPlot();
//                settter_values_to_Plot(categoryplot);
//                settter_values_to_Plot_Pie((PiePlot) plot.getPieChart().getPlot());

                return chart;
                // </editor-fold>
            }
            case 17: {//Metercharet
                // <editor-fold defaultstate="collapsed" desc="meterplot">
                MeterPlot plot = new MeterPlot((ValueDataset) ds);

                plot.setRange(new Range(0.0D, 80.0D));
                plot.addInterval(new MeterInterval("Normal", new Range(0.0D, 35.0D), Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
                plot.addInterval(new MeterInterval("Warning", new Range(35.0D, 50.0D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
                plot.addInterval(new MeterInterval("Critical", new Range(50.0D, 80.0D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128)));
                plot.setNeedlePaint(Color.darkGray);
                plot.setDialBackgroundPaint(Color.white);
                plot.setDialOutlinePaint(Color.gray);
                plot.setDialShape(DialShape.CHORD);
//                plot.setMeterAngle(260);
                plot.setMeterAngle(180);
                plot.setTickLabelsVisible(true);
//                plot.setTickLabelFont(new Font("Dialog", 1, 10));
//                plot.setTickLabelPaint(Color.darkGray);
                plot.setTickSize(20.0D);
                plot.setTickPaint(Color.lightGray);
                plot.setValuePaint(Color.black);
//                plot.setValueFont(new Font("Dialog", 1, 14));

                JFreeChart chart = new JFreeChart(TITLE, CHART_TITLE_FONT, plot, LEGEND);

//                JFreeChart chart = ChartFactory.createMultiplePieChart3D(TITLE, (DefaultCategoryDataset) ds, TableOrder.BY_ROW, LEGEND, TOOLTIP, URL);
                settter_values_to_char(chart);
//
//                MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();

//                CategoryPlot categoryplot = chart.getCategoryPlot();
//                settter_values_to_Plot(categoryplot);
//                settter_values_to_Plot_Pie((PiePlot) plot.getPieChart().getPlot());

                return chart;
                // </editor-fold>
            }
            case 18: {//percentagebarchart
                // <editor-fold defaultstate="collapsed" desc="percentagebarchart">
                JFreeChart chart = ChartFactory.createStackedBarChart(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);

                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            case 19: {//percentagebarchart3d
                // <editor-fold defaultstate="collapsed" desc="percentagebarchart3d">
                JFreeChart chart = ChartFactory.createStackedBarChart3D(TITLE, LABEL_X, LABEL_Y, ((DefaultCategoryDataset) ds), ORIENTATION == 0 ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, LEGEND, TOOLTIP, URL);

                settter_values_to_char(chart);
                CategoryPlot categoryplot = chart.getCategoryPlot();
                settter_values_to_Plot(categoryplot);

                return chart;
                // </editor-fold>
            }
            default: {
//                System.out.println("@@@@");
                return null;
            }
        }
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getTITLE() {
        return TITLE;
    }

    public void settter_values_to_char(JFreeChart chart) {
        if (LEGEND) {
            chart.getLegend().setBorder(LEGEND_BORDER / 2, LEGEND_BORDER, LEGEND_BORDER / 2, LEGEND_BORDER);
            chart.getLegend().setItemFont(LEGEND_FONT);
            chart.getLegend().setPosition(LEGEND_POSITIION);

            chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
            chart.getLegend().setItemPaint(LEGEND_COLOR);
        }

//        chart.getTitle().setExpandToFitSpace(true);
//        chart.getTitle().setVisible(CHART_TITLE);
        chart.getTitle().setHeight(1);
        chart.getTitle().setText("");
        chart.getTitle().setVisible(true);
        chart.getTitle().setFont(CHART_TITLE_FONT);
        chart.getTitle().setPaint(CHART_TITLE_COLOR);
        chart.getTitle().setPosition(CHART_TITLE_POSITIION);

        chart.setBorderVisible(CHART_BORDER);
        chart.setBorderPaint(CHART_BORDER_COLOR);
        chart.setBorderStroke(CHART_BORDER_STROKE);
    }

    public void settter_values_to_Plot(CategoryPlot categoryplot) {

        categoryplot.setRenderer(0, Custom_Renderer.renderer_by_type_chart(ds, type_chart, URL, PLOT_GRAPHIC_BORDER, PLOT_GRAPHIC_SHADOW, false));
//        System.out.println("Despues de renderear");

        categoryplot.setForegroundAlpha(PLOT_ALPHA_FOREGROUND);
        categoryplot.setAxisOffset(new RectangleInsets(PLOT_OFFSET, PLOT_OFFSET, PLOT_OFFSET, PLOT_OFFSET));
        categoryplot.setBackgroundPaint(PLOT_BACKGROUND);

        categoryplot.setOutlineVisible(PLOT_OUTLINE);
        categoryplot.setOutlineStroke(PLOT_OUTLINE_STROKE);
        categoryplot.setOutlinePaint(PLOT_OUTLINE_COLOR);



        categoryplot.setDomainGridlinesVisible(DOMAIN_LINES);
        categoryplot.setDomainGridlineStroke(DOMAIN_LINE_STROKE);
        categoryplot.setDomainGridlinePaint(DOMAIN_LINE_COLOR);

        categoryplot.setRangeGridlinesVisible(RANGE_LINES);
        categoryplot.setRangeGridlineStroke(RANGE_LINE_STROKE);
        categoryplot.setRangeGridlinePaint(RANGE_LINE_COLOR);

        CategoryAxis eje_x = categoryplot.getDomainAxis();

        if (X_ANGLE >= 0) {
            eje_x.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(X_ANGLE));
        } else if (X_ANGLE < 0) {
            eje_x.setCategoryLabelPositions(CategoryLabelPositions.createDownRotationLabelPositions(X_ANGLE));
        }

        eje_x.setLabelAngle(X_LABEL_ANGLE);
        eje_x.setLabelFont(X_LABEL_FONT);
        eje_x.setLabelPaint(X_LABEL_COLOR);

        eje_x.setAxisLinePaint(X_AXISLINE_COLOR);
        eje_x.setAxisLineStroke(X_AXISLINE_STROKE);

        eje_x.setTickLabelFont(X_AXISTICK_FONT);
        eje_x.setTickLabelPaint(X_AXISTICK_COLOR);

        eje_x.setTickMarksVisible(X_AXISTICKMARKS);
        eje_x.setTickMarkPaint(X_AXISTICKMARKS_COLOR);
        eje_x.setTickMarkStroke(X_AXISTICKMARKS_STROKE);

        CategoryLabelPositions x_label_p = eje_x.getCategoryLabelPositions();

        CategoryLabelPosition top = new CategoryLabelPosition(
                x_label_p.getLabelPosition(RectangleEdge.TOP).getCategoryAnchor(),
                X_LABEL_POSITION.isEmpty()? TextBlockAnchor.BOTTOM_CENTER: obtenerTextBlockAnchor("top", X_LABEL_POSITION),
                x_label_p.getLabelPosition(RectangleEdge.TOP).getRotationAnchor(),
                x_label_p.getLabelPosition(RectangleEdge.TOP).getAngle(),
                x_label_p.getLabelPosition(RectangleEdge.TOP).getWidthType(),
                x_label_p.getLabelPosition(RectangleEdge.TOP).getWidthRatio());

        CategoryLabelPosition right = new CategoryLabelPosition(
                x_label_p.getLabelPosition(RectangleEdge.RIGHT).getCategoryAnchor(),
                X_LABEL_POSITION.isEmpty()? TextBlockAnchor.CENTER_LEFT: obtenerTextBlockAnchor("center", X_LABEL_POSITION),
                x_label_p.getLabelPosition(RectangleEdge.RIGHT).getRotationAnchor(),
                x_label_p.getLabelPosition(RectangleEdge.RIGHT).getAngle(),
                x_label_p.getLabelPosition(RectangleEdge.RIGHT).getWidthType(),
                x_label_p.getLabelPosition(RectangleEdge.RIGHT).getWidthRatio());

        CategoryLabelPosition left = new CategoryLabelPosition(
                x_label_p.getLabelPosition(RectangleEdge.LEFT).getCategoryAnchor(),
                X_LABEL_POSITION.isEmpty()? TextBlockAnchor.CENTER_RIGHT: obtenerTextBlockAnchor("center", X_LABEL_POSITION),
                x_label_p.getLabelPosition(RectangleEdge.LEFT).getRotationAnchor(),
                x_label_p.getLabelPosition(RectangleEdge.LEFT).getAngle(),
                x_label_p.getLabelPosition(RectangleEdge.LEFT).getWidthType(),
                x_label_p.getLabelPosition(RectangleEdge.LEFT).getWidthRatio());

        CategoryLabelPosition bottom = new CategoryLabelPosition(
                x_label_p.getLabelPosition(RectangleEdge.BOTTOM).getCategoryAnchor(),
                X_LABEL_POSITION.isEmpty()? TextBlockAnchor.TOP_CENTER: obtenerTextBlockAnchor("top", X_LABEL_POSITION),
                x_label_p.getLabelPosition(RectangleEdge.BOTTOM).getRotationAnchor(),
                x_label_p.getLabelPosition(RectangleEdge.BOTTOM).getAngle(),
                x_label_p.getLabelPosition(RectangleEdge.BOTTOM).getWidthType(),
                x_label_p.getLabelPosition(RectangleEdge.BOTTOM).getWidthRatio());

        eje_x.setCategoryLabelPositions(new CategoryLabelPositions(top, bottom, left, right));


        ValueAxis eje_y = categoryplot.getRangeAxis();

        eje_y.setLabelAngle(Y_LABEL_ANGLE);
        eje_y.setLabelFont(Y_LABEL_FONT);
        eje_y.setLabelPaint(Y_LABEL_COLOR);

        eje_y.setAxisLinePaint(Y_AXISLINE_COLOR);
        eje_y.setAxisLineStroke(Y_AXISLINE_STROKE);

        eje_y.setTickLabelFont(Y_AXISTICK_FONT);
        eje_y.setTickLabelPaint(Y_AXISTICK_COLOR);

        eje_y.setTickMarksVisible(Y_AXISTICKMARKS);
        eje_y.setTickMarkPaint(Y_AXISTICKMARKS_COLOR);
        eje_y.setTickMarkStroke(Y_AXISTICKMARKS_STROKE);

        if (type_chart == 18) {
            //formato para que el eje y salga en porcentajes
            NumberAxis localNumberAxis = (NumberAxis) categoryplot.getRangeAxis();
            localNumberAxis.setNumberFormatOverride(new DecimalFormat("0%"));
            eje_y.resizeRange(1.1, 0.575);
        }


        if (Y_RANGE[0] != null & Y_RANGE[1] != null) {
            try {
                if ((Y_RANGE[0] - Y_RANGE[1]) != 0) {
                    eje_y.setRange(Y_RANGE[0], Y_RANGE[1]);
                }
            } catch (Exception ep) {
            }
        }

//        System.out.println("ds2>" + ds2 + "::" + ((DefaultCategoryDataset) ds2).getRowCount());
        if (ds2 != null && ((DefaultCategoryDataset) ds2).getRowCount() > 0) {
//            System.out.println(">>" + ((DefaultCategoryDataset) ds2).getGroup().getID());
//            System.out.println(">>" + ((DefaultCategoryDataset) ds2).getRowKeys().get(0));
            ValueAxis eje_y2 = null;
            if (Y2_AXIS_TYPE == 0) {//Numeric
                eje_y2 = new NumberAxis("" + ((DefaultCategoryDataset) ds2).getRowKeys().get(0));
                ((NumberAxis) eje_y2).setNumberFormatOverride(new DecimalFormat("##,##0.00"));
            } else if (Y2_AXIS_TYPE == 1) {//Integer
//                System.out.println("");
                eje_y2 = new NumberAxis("" + ((DefaultCategoryDataset) ds2).getRowKeys().get(0));
                ((NumberAxis) eje_y2).setNumberFormatOverride(NumberFormat.getIntegerInstance());
            } else if (Y2_AXIS_TYPE == 2) {//Moneda o double
                eje_y2 = new NumberAxis("" + ((DefaultCategoryDataset) ds2).getRowKeys().get(0));
                ((NumberAxis) eje_y2).setNumberFormatOverride(new DecimalFormat("S/ ##,##0.00"));
            } else if (Y2_AXIS_TYPE == 3) {//porcentaje
                eje_y2 = new NumberAxis("" + ((DefaultCategoryDataset) ds2).getRowKeys().get(0));
                ((NumberAxis) eje_y2).setNumberFormatOverride(NumberFormat.getPercentInstance());
                ((NumberAxis) eje_y2).setNumberFormatOverride(new DecimalFormat("## %"));
            }

            ((NumberAxis) eje_y2).setLabel(LABEL_Y2);
            ((NumberAxis) eje_y2).setLabelAngle(Y2_LABEL_ANGLE);
            ((NumberAxis) eje_y2).setLabelFont(Y2_LABEL_FONT);
            ((NumberAxis) eje_y2).setLabelPaint(Y2_LABEL_COLOR);

            ((NumberAxis) eje_y2).setAxisLinePaint(Y2_AXISLINE_COLOR);
            ((NumberAxis) eje_y2).setAxisLineStroke(Y2_AXISLINE_STROKE);

            ((NumberAxis) eje_y2).setTickLabelFont(Y2_AXISTICK_FONT);
            ((NumberAxis) eje_y2).setTickLabelPaint(Y2_AXISTICK_COLOR);

            ((NumberAxis) eje_y2).setTickMarksVisible(Y2_AXISTICKMARKS);
            ((NumberAxis) eje_y2).setTickMarkPaint(Y2_AXISTICKMARKS_COLOR);
            ((NumberAxis) eje_y2).setTickMarkStroke(Y2_AXISTICKMARKS_STROKE);

            if (Y2_RANGE[0] != null & Y2_RANGE[1] != null) {
                try {
                    if ((Y2_RANGE[0] - Y2_RANGE[1]) != 0) {
                        eje_y2.setRange(Y2_RANGE[0], Y2_RANGE[1]);
                    }
                } catch (Exception ep) {
                }
            }

            categoryplot.setDataset(1, (DefaultCategoryDataset) ds2);
            categoryplot.mapDatasetToRangeAxis(1, 1);
            categoryplot.setRangeAxis(1, eje_y2);

            System.out.println(">>" + categoryplot.getRenderer());
            System.out.println(">>" + categoryplot.getRenderer().getClass());
//            categoryplot.setRenderer(1, Custom_Renderer.renderer_by_type_chart(ds2, 8, URL, PLOT_GRAPHIC_BORDER, PLOT_GRAPHIC_SHADOW, true));
            categoryplot.setRenderer(1, Custom_Renderer.renderer_by_type_chart(ds2, 15, URL, PLOT_GRAPHIC_BORDER, PLOT_GRAPHIC_SHADOW, true));

//            categoryplot.getRenderer(1).setSeriesVisibleInLegend(0, false);

            categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
        }

        if (URL) {
            //StandardCategoryURLGenerator lara = new StandardCategoryURLGenerator(URL_LINK_1, URL_LINK_2, URL_LINK_3) {
            StandardCategoryURLGenerator lara = new StandardCategoryURLGenerator() {
                @Override
                public String generateURL(CategoryDataset dataset, int series, int category) {
                    //String url = URL_LINK_1;
                    String url = "";
                    Comparable series_value_Key = ((acceso.dashboard.DefaultCategoryDataset) dataset).getRowValueKey(series);

                    String series_value_url = ((acceso.dashboard.DefaultCategoryDataset) dataset).getRowValueUrl(series);
//                    String series_value_code = ((acceso.dashboard.DefaultCategoryDataset) dataset).getRowCodeKey(series);

                    if (series_value_url.contentEquals("")) {
                        url = "#";
                    } else {
                        if (series_value_url.split(";").length == 3) {
//                            Comparable seriesKey = dataset.getRowKey(series);
                            Comparable seriesKey = dataset.getRowKey(series);
                            
                            System.out.println("seriesKey:"+seriesKey);
                            Comparable categoryKey = dataset.getColumnKey(category);
                            boolean firstParameter = url.indexOf("?") == -1;
                            url += firstParameter ? "?" : "&amp;";
//                            String series_value_code = ((acceso.dashboard.DefaultCategoryDataset) dataset).getRowCodeKey(category);
                            String series_value_code = ""+((acceso.dashboard.DefaultCategoryDataset) dataset).getColumnKey_value(category);

                            String[] LINKS = series_value_url.split(";");
                            if (LINKS[0].indexOf("pospag") > -1) {
                                try {
//                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + URLEncoder.encode(categoryKey.toString(), "ISO-8859-1") + "')";
//                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + seriesKey+ "')";
//                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + categoryKey+ "')";
                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + series_value_code+ "')";
                                } catch (Exception ep) {
                                }
                            } else {
                                try {
                                    url += LINKS[1] + "=" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }

                                try {
                                    url += "&amp;" + LINKS[2] + "=" + URLEncoder.encode(series_value_code.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }
                            }


                        } else {
                            url = "#";
                        }
                    }



                    return url;
                }
            };
            categoryplot.getRenderer(0).setItemURLGenerator(lara);
            if (ds2 != null && ((DefaultCategoryDataset) ds2).getRowCount() > 0) {
                categoryplot.getRenderer(1).setItemURLGenerator(lara);
            }
        }
        if (TOOLTIP) {
            categoryplot.getRenderer(0).setToolTipGenerator(new StandardCategoryToolTipGenerator());
            if (ds2 != null && ((DefaultCategoryDataset) ds2).getRowCount() > 0) {
                categoryplot.getRenderer(1).setToolTipGenerator(new StandardCategoryToolTipGenerator());
            }
        }
        System.out.println("LABEL: "+LABEL+" - PAGINA: "+co_pagina);
        if (LABEL) {
            StandardCategoryItemLabelGenerator label_geerator = new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getIntegerInstance());
//            CategoryItemLabelGenerator label_geerator2 = new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getIntegerInstance());
            
            
            categoryplot.getRenderer(0).setBaseItemLabelGenerator(label_geerator);
            
            categoryplot.getRenderer(0).setBaseItemLabelsVisible(LABEL);
            categoryplot.getRenderer(0).setBaseItemLabelFont(LABEL_FONT);
            
            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0); 
//            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.HALF_ASCENT_RIGHT, TextAnchor.HALF_ASCENT_RIGHT, 0.0); 
            
//            categoryplot.getRenderer(0).setBasePositiveItemLabelPosition(position);

            if (ds2 != null && ((DefaultCategoryDataset) ds2).getRowCount() > 0) {
//                categoryplot.getRenderer(1).setBaseItemLabelGenerator(label_geerator);
//                categoryplot.getRenderer(1).setBaseItemLabelsVisible(LABEL);
//                categoryplot.getRenderer(1).setBaseItemLabelFont(LABEL_FONT);
//                categoryplot.addAnnotation(new CategoryLineAnnotation(height, X_ANGLE, LABEL_Y2, X_ANGLE, LEGEND_COLOR, RANGE_LINE_STROKE));
            }
        }else{
            categoryplot.getRenderer(0).setBaseItemLabelsVisible(LABEL);
        }

    }

    public void settter_values_to_Plot_Pie(PiePlot plot) {
        plot.setForegroundAlpha(PLOT_ALPHA_FOREGROUND);
        plot.setBackgroundPaint(PLOT_BACKGROUND);

        plot.setOutlineVisible(PLOT_OUTLINE);
        plot.setOutlinePaint(PLOT_OUTLINE_COLOR);
        plot.setOutlineStroke(PLOT_OUTLINE_STROKE);

        plot.setCircular(true);
        plot.setInteriorGap(0.09);

        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);

        plot.setSimpleLabels(LABEL_TYPE == 1 ? true : false);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(LABEL_FORMAT));
        plot.setSimpleLabelOffset(LABEL_OFFSET);
        plot.setLabelOutlinePaint(LABEL_OUTLINECOLOR);
        plot.setLabelBackgroundPaint(LABEL_BACKGROUNDCOLOR);
        plot.setLabelShadowPaint(LABEL_SHADOWCOLOR);
        plot.setLabelFont(LABEL_FONT);

        if (URL) {
            StandardPieURLGenerator lara = new StandardPieURLGenerator() {
                @Override
                public String generateURL(PieDataset dataset, Comparable key, int pieIndex) {
                    String url = "";
                    System.out.println("[key:" + key + "::" + ((DefaultPieDataset) dataset).getValue(key) + "::" + ((DefaultPieDataset) dataset).getKeys_value(key) + "::" + ((DefaultPieDataset) dataset).getKeys_url_values(key) + "][pieIndex:" + pieIndex + "]");


                    Comparable series_value_Key = ((DefaultPieDataset) dataset).getKeys_value(key);

                    String series_value_url = ((DefaultPieDataset) dataset).getKeys_url_values(key);
                    if (series_value_url.contentEquals("")) {
                        url = "#";
                    } else {
                        if (series_value_url.split(";").length == 3) {
                            boolean firstParameter = url.indexOf("?") == -1;
                            url += firstParameter ? "?" : "&amp;";

                            String[] LINKS = series_value_url.split(";");
                            if (LINKS[0].indexOf("pospag") > -1) {
                                try {
                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + URLEncoder.encode(key.toString(), "ISO-8859-1") + "')";
                                } catch (Exception ep) {
                                }
                            } else {
                                try {
                                    url += LINKS[1] + "=" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }

                                try {
                                    url += "&amp;" + LINKS[2] + "=" + URLEncoder.encode(key.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }
                            }


                        } else {
                            url = "#";
                        }
                    }
                    return url;
                }
            };
            plot.setURLGenerator(lara);
        }

        if (TOOLTIP) {
            plot.setToolTipGenerator(new StandardPieToolTipGenerator());
        }
        plot.setShadowPaint(null);
        plot.setDirection(Rotation.CLOCKWISE);
        Comparable key = null;

        Iterator iterator = plot.getDataset().getKeys().iterator();
        while (iterator.hasNext()) {
            key = (Comparable) iterator.next();
            for (int i = 0; i < explodes.size(); i++) {
                if (key.equals(explodes.get(i))) {
                    plot.setExplodePercent(key, 0.2);
                }
            }
        }

        List<Comparable> keys = plot.getDataset().getKeys();
        int aInt;

        for (int i = 0; i < keys.size(); i++) {
            aInt = i % Custom_Renderer.colors.length;
            plot.setSectionPaint(keys.get(i), Custom_Renderer.colors[aInt]);
        }

    }

    public void settter_values_to_Plot_MultiplePie(MultiplePiePlot plot) {
//        ((PiePlot)plot);
        System.out.println("aqui");
        plot.setForegroundAlpha(PLOT_ALPHA_FOREGROUND);
        plot.setBackgroundPaint(PLOT_BACKGROUND);

        plot.setOutlineVisible(PLOT_OUTLINE);
        plot.setOutlinePaint(PLOT_OUTLINE_COLOR);
        plot.setOutlineStroke(PLOT_OUTLINE_STROKE);

        plot.setAggregatedItemsPaint(Color.RED);


//        ((PiePlot) plot.getPieChart().getPlot()).setBaseSectionPaint(Color.red);
//        ((PiePlot) plot.getPieChart().getPlot()).setBaseSectionOutlinePaint(Color.GREEN);
        ((PiePlot) plot.getPieChart().getPlot()).setBaseSectionOutlineStroke(new BasicStroke(0));


        ((PiePlot) plot.getPieChart().getPlot()).setForegroundAlpha(PLOT_ALPHA_FOREGROUND);
        ((PiePlot) plot.getPieChart().getPlot()).setBackgroundPaint(PLOT_BACKGROUND);

        ((PiePlot) plot.getPieChart().getPlot()).setOutlineVisible(PLOT_OUTLINE);
        ((PiePlot) plot.getPieChart().getPlot()).setOutlinePaint(PLOT_OUTLINE_COLOR);
        ((PiePlot) plot.getPieChart().getPlot()).setOutlineStroke(PLOT_OUTLINE_STROKE);



        ((PiePlot) plot.getPieChart().getPlot()).setCircular(true);
        ((PiePlot) plot.getPieChart().getPlot()).setInteriorGap(0.09);

        ((PiePlot) plot.getPieChart().getPlot()).setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);

        ((PiePlot) plot.getPieChart().getPlot()).setSimpleLabels(LABEL_TYPE == 1 ? true : false);
        ((PiePlot) plot.getPieChart().getPlot()).setLabelGenerator(new StandardPieSectionLabelGenerator(LABEL_FORMAT));
        ((PiePlot) plot.getPieChart().getPlot()).setSimpleLabelOffset(LABEL_OFFSET);
        ((PiePlot) plot.getPieChart().getPlot()).setLabelOutlinePaint(LABEL_OUTLINECOLOR);
        ((PiePlot) plot.getPieChart().getPlot()).setLabelBackgroundPaint(LABEL_BACKGROUNDCOLOR);
        ((PiePlot) plot.getPieChart().getPlot()).setLabelShadowPaint(LABEL_SHADOWCOLOR);
        ((PiePlot) plot.getPieChart().getPlot()).setLabelFont(LABEL_FONT);

//        if (URL) {
//            StandardPieURLGenerator lara = new StandardPieURLGenerator() {
//                @Override
//                public String generateURL(PieDataset dataset, Comparable key, int pieIndex) {
//                    String url = "";
//                    System.out.println("[key:" + key + "::" + ((DefaultPieDataset) dataset).getValue(key) + "::" + ((DefaultPieDataset) dataset).getKeys_value(key) + "::" + ((DefaultPieDataset) dataset).getKeys_url_values(key) + "][pieIndex:" + pieIndex + "]");
//
//
//                    Comparable series_value_Key = ((DefaultPieDataset) dataset).getKeys_value(key);
//
//                    String series_value_url = ((DefaultPieDataset) dataset).getKeys_url_values(key);
//                    if (series_value_url.contentEquals("")) {
//                        url = "#";
//                    } else {
//                        if (series_value_url.split(";").length == 3) {
//                            boolean firstParameter = url.indexOf("?") == -1;
//                            url += firstParameter ? "?" : "&amp;";
//
//                            String[] LINKS = series_value_url.split(";");
//                            if (LINKS[0].indexOf("pospag") > -1) {
//                                try {
//                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + URLEncoder.encode(key.toString(), "ISO-8859-1") + "')";
//                                } catch (Exception ep) {
//                                }
//                            } else {
//                                try {
//                                    url += LINKS[1] + "=" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1");
//                                } catch (Exception ep) {
//                                }
//
//                                try {
//                                    url += "&amp;" + LINKS[2] + "=" + URLEncoder.encode(key.toString(), "ISO-8859-1");
//                                } catch (Exception ep) {
//                                }
//                            }
//
//
//                        } else {
//                            url = "#";
//                        }
//                    }
//                    return url;
//                }
//            };
//            ((PiePlot)plot.getPieChart().getPlot()).setURLGenerator(lara);
//        }

        if (TOOLTIP) {
            ((PiePlot) plot.getPieChart().getPlot()).setToolTipGenerator(new StandardPieToolTipGenerator());
        }
        ((PiePlot) plot.getPieChart().getPlot()).setShadowPaint(null);
        ((PiePlot) plot.getPieChart().getPlot()).setDirection(Rotation.CLOCKWISE);
//        Comparable key = null;
//
//        Iterator iterator = ((PiePlot)plot.getPieChart().getPlot()).getDataset().getKeys().iterator();
//        while (iterator.hasNext()) {
//            key = (Comparable) iterator.next();
//            for (int i = 0; i < explodes.size(); i++) {
//                if (key.equals(explodes.get(i))) {
//                    ((PiePlot)plot.getPieChart().getPlot()).setExplodePercent(key, 0.2);
//                }
//            }
//        }

        try {
            List<Comparable> keys = plot.getDataset().getColumnKeys();
            int aInt;
            for (int i = 0; i < keys.size(); i++) {
                aInt = i % Custom_Renderer.colors.length;
                ((PiePlot) plot.getPieChart().getPlot()).setSectionPaint(keys.get(i), Custom_Renderer.colors[aInt]);
            }
        } catch (Exception ep) {
            System.out.println(">" + ep);
        }

    }

    public void settter_values_to_Plot_Ring(RingPlot plot) {
        plot.setForegroundAlpha(PLOT_ALPHA_FOREGROUND);
        plot.setBackgroundPaint(PLOT_BACKGROUND);

        plot.setOutlineVisible(PLOT_OUTLINE);
        plot.setOutlinePaint(PLOT_OUTLINE_COLOR);
        plot.setOutlineStroke(PLOT_OUTLINE_STROKE);

        plot.setCircular(true);
        plot.setInteriorGap(0.09);

        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);

        plot.setSimpleLabels(LABEL_TYPE == 1 ? true : false);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(LABEL_FORMAT));
        plot.setSimpleLabelOffset(LABEL_OFFSET);
        plot.setSeparatorsVisible(false);
        plot.setSectionDepth(PLOT_DEPTH);
        plot.setLabelOutlinePaint(LABEL_OUTLINECOLOR);
        plot.setLabelBackgroundPaint(LABEL_BACKGROUNDCOLOR);
        plot.setLabelShadowPaint(LABEL_SHADOWCOLOR);
        plot.setLabelFont(LABEL_FONT);


        if (URL) {
            StandardPieURLGenerator lara = new StandardPieURLGenerator() {
                @Override
                public String generateURL(PieDataset dataset, Comparable key, int pieIndex) {
                    String url = "";
                    System.out.println("[key:" + key + "::" + ((DefaultPieDataset) dataset).getValue(key) + "::" + ((DefaultPieDataset) dataset).getKeys_value(key) + "::" + ((DefaultPieDataset) dataset).getKeys_url_values(key) + "][pieIndex:" + pieIndex + "]");


                    Comparable series_value_Key = ((DefaultPieDataset) dataset).getKeys_value(key);

                    String series_value_url = ((DefaultPieDataset) dataset).getKeys_url_values(key);
                    if (series_value_url.contentEquals("")) {
                        url = "#";
                    } else {
                        if (series_value_url.split(";").length == 3) {
                            boolean firstParameter = url.indexOf("?") == -1;
                            url += firstParameter ? "?" : "&amp;";

                            String[] LINKS = series_value_url.split(";");
                            if (LINKS[0].indexOf("pospag") > -1) {
                                try {
                                    url = "javascript:valpagpospagi(" + co_pagina + "," + id_frawor + "," + co_conten + ",'" + LINKS[1] + "','" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1") + "','" + LINKS[2] + "','" + URLEncoder.encode(key.toString(), "ISO-8859-1") + "')";
                                } catch (Exception ep) {
                                }
                            } else {
                                try {
                                    url += LINKS[1] + "=" + URLEncoder.encode(series_value_Key.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }

                                try {
                                    url += "&amp;" + LINKS[2] + "=" + URLEncoder.encode(key.toString(), "ISO-8859-1");
                                } catch (Exception ep) {
                                }
                            }


                        } else {
                            url = "#";
                        }
                    }
                    return url;
                }
            };
            plot.setURLGenerator(lara);
        }

        if (TOOLTIP) {
            plot.setToolTipGenerator(new StandardPieToolTipGenerator(TOOLTIP_FORMAT));
        }
        plot.setShadowPaint(null);
        plot.setDirection(Rotation.CLOCKWISE);
        Comparable key = null;

        Iterator iterator = plot.getDataset().getKeys().iterator();
        while (iterator.hasNext()) {
            key = (Comparable) iterator.next();
            for (int i = 0; i < explodes.size(); i++) {
                if (key.equals(explodes.get(i))) {
                    plot.setExplodePercent(key, 0.2);
                }
            }
        }

        List<Comparable> keys = plot.getDataset().getKeys();
        int aInt;

        for (int i = 0; i < keys.size(); i++) {
            aInt = i % Custom_Renderer.colors.length;
            plot.setSectionPaint(keys.get(i), Custom_Renderer.colors[aInt]);
        }

    }
    
    private TextBlockAnchor obtenerTextBlockAnchor(String primer_orden, String segundo_orden){
        if(primer_orden.equals("bottom")){
            if(segundo_orden.equals("center"))return TextBlockAnchor.BOTTOM_CENTER;
            else if(segundo_orden.equals("left"))return TextBlockAnchor.BOTTOM_LEFT;
            else if(segundo_orden.equals("right"))return TextBlockAnchor.BOTTOM_RIGHT;
        }else if(primer_orden.equals("center")){
            if(segundo_orden.equals("center"))return TextBlockAnchor.CENTER;
            else if(segundo_orden.equals("left"))return TextBlockAnchor.CENTER_LEFT;
            else if(segundo_orden.equals("right"))return TextBlockAnchor.CENTER_RIGHT;
        }else if(primer_orden.equals("top")){
            if(segundo_orden.equals("center"))return TextBlockAnchor.TOP_CENTER;
            else if(segundo_orden.equals("left"))return TextBlockAnchor.TOP_LEFT;
            else if(segundo_orden.equals("right"))return TextBlockAnchor.TOP_RIGHT;
        }
        
        return null;
    }

    public static void main(String[] args) {
        DocumentBuilderFactory FACTORY;
        DocumentBuilder BUILDER;
        Document DOCUMENT;
        try {
            FACTORY = DocumentBuilderFactory.newInstance();
            BUILDER = FACTORY.newDocumentBuilder();
            DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/Documentos/wfi2.xml"));
            WorkflowImageUtil wf_util = new WorkflowImageUtil(DOCUMENT);
            JFreeChart chart = wf_util.proces();
            JFrame frame = new JFrame("Imagen");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            ChartPanel panel = new ChartPanel(chart);
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);
        } catch (Exception ep) {
            System.out.println(">" + ep.getMessage());
        }
    }
}